﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebAsbesto.CDC
{
    public partial class CDCAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] != "1")
                Response.Redirect("Login/Login.aspx");
            else if (Session["User"] == "1")
            {
                //PAGE LOAD ACA!
            }
        }

        public void Limpiar_Formulario()
        {
            txt_Fecha_Envio.Text = "";
            txt_Nota.Text = "";
        }

        protected void btn_Aceptar_Volver_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect("CDCShowTable.aspx");
        }

        public bool Validar_Registros()
        {
            if (txt_Fecha_Envio .Text != "")
                return true;
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", "alert('Debe Completar todos los campos Obligatorios');", true);
                return false;
            }
        }

        public void Grabar_BD()
        {
            if (Validar_Registros())
            {
                string Consulta;

                Consulta = "EXEC CDC_A " + ddl_Id_Obra.SelectedValue + ", '" + txt_Fecha_Envio.Text + "' , '" + txt_Nota.Text + "'";

                Funciones.Insert_DataBase(Consulta);
            }
        }

        protected void btn_Aceptar_Cargar_Otro_Click(object sender, EventArgs e)
        {
            Grabar_BD();
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Ok", "alert('Cadena de Custodia agregada con exito');", true);
            Page.Response.Redirect("CDC_MuestrasAdd.aspx");
        }
    }
}